package logica;

import java.util.Vector;

import javax.swing.table.DefaultTableModel;

public class MyTableModel extends DefaultTableModel {
	
	private boolean ImInLoop = false;
	
    public MyTableModel() {
      super(new String[]{"Apellido", "Nombre", "Nro. de documento", "Responsable"}, 0);
    }

    @Override
    public Class<?> getColumnClass(int columnIndex) {
      Class clazz = String.class;
      if (columnIndex ==2)
          clazz = Integer.class;
      else if(columnIndex ==3)
          clazz = Boolean.class;
      return clazz;
    }

    @Override
    public boolean isCellEditable(int row, int column) {
      return column == 3;
    }

    @Override
    public void setValueAt(Object aValue, int row, int column) {
      if (aValue instanceof Boolean && column == 3) {
    	 
    	  System.out.println(aValue);
          Vector rowData = (Vector)getDataVector().get(row);
          rowData.set(3, (boolean)aValue);
          fireTableCellUpdated(row, column);
    	  
    	  if (!ImInLoop) {
              ImInLoop = true;
              Boolean bol = (Boolean) aValue;
              super.setValueAt(aValue, row, column);
              for (int i = 0; i < this.getRowCount(); i++) {
                  if (i != row) {
                      super.setValueAt(!bol, i, column);
                  }
              }
              ImInLoop = false;
          }
      }
      else {
          super.setValueAt(aValue, row, column);
      }
    }
    

}











































/*
 * 
 * import java.awt.Color;
import java.awt.Component;

import javax.swing.DefaultCellEditor;
import javax.swing.JCheckBox;
import javax.swing.JComponent;
import javax.swing.JLabel;
import javax.swing.JTable;
import javax.swing.table.DefaultTableModel;
import javax.swing.table.TableCellRenderer;
 * public class Render extends DefaultCellEditor implements TableCellRenderer{
	private JComponent component = new JCheckBox();    
	private boolean value = false; // valor de la celda

	*//** Constructor de clase *//*
	public Render(){
	    super( new JCheckBox() );
	}

	*//** retorna valor de celda *//*
	@Override
	public Object getCellEditorValue() {
	    return ((JCheckBox)component).isSelected();        
	}	
	public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected,
			boolean hasFocus, int row, int column) {

		DefaultTableModel model = (DefaultTableModel) table.getModel();
		JCheckBox check=new JCheckBox();
		JLabel lbl= new JLabel();


	if(model.getValueAt(row,column).getClass().equals(Boolean.class)){
		check.setSelected(Boolean.parseBoolean(model.getValueAt(row,column).toString()));
		return check;
    }

    if (column<3){
    	lbl.setText(" "+model.getValueAt(row,column).toString());
        return lbl;
    }

    return  lbl;


	}
}


*//** Segun el valor de la celda selecciona/deseleciona el JCheckBox *//*
@Override
public Component getTableCellEditorComponent(JTable table, Object value, boolean isSelected, int row, int column) {
    //Color de fondo en modo edicion
    ( (JCheckBox) component).setBackground( new Color(200,200,0) );
    //obtiene valor de celda y coloca en el JCheckBox
    boolean b = ((Boolean) value).booleanValue();
    ( (JCheckBox) component).setSelected( b );
    return ( (JCheckBox) component);     
}

*//** cuando termina la manipulacion de la celda *//*
@Override
public boolean stopCellEditing() {        
    value = ((Boolean)getCellEditorValue()).booleanValue() ;
    ((JCheckBox)component).setSelected( value );
    return super.stopCellEditing();
}

*//** retorna componente *//*
public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected, boolean hasFocus, int row, int column) {
     if (value == null)
        return null;         
     return ( (JCheckBox) component );
}

}
*/